//package com.example.behaviour.handler;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import io.netty.channel.Channel;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.SimpleChannelInboundHandler;
//import io.netty.channel.group.ChannelGroup;
//import io.netty.channel.group.DefaultChannelGroup;
//import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
//import io.netty.util.concurrent.GlobalEventExecutor;
//import lombok.extern.slf4j.Slf4j;
//
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Set;
//import java.util.UUID;
//import java.util.concurrent.ConcurrentHashMap;
//
//@Slf4j
//public class AudioRequestHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
//
//    public static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
//
//    private static ConcurrentHashMap<String,Channel> cmap = new ConcurrentHashMap();
//
//    @Override
//    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        System.out.println("与客户端建立连接，通道开启！");
//    }
//
//    @Override
//    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
//        System.out.println("与客户端断开连接，通道关闭！");
//    }
//
//    @Override
//    protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) throws Exception {
//        JSONObject jsonObject = JSONObject.parseObject(msg.text());
//        System.out.println(jsonObject.toJSONString());
//        if(jsonObject.containsKey("name")){
//            Map message = JSON.parseObject(msg.text(), Map.class);
//            System.out.println("message "+message.get("name"));
//            websocketLogin(message,ctx);
//            String to = message.get("name").toString();
//
//            Set<Map.Entry<String, Channel>> entries = cmap.entrySet();
//            for (Map.Entry<String, Channel> entry : entries) {
////                if(!entry.getKey().equals(to)){//将消息转发到其他非自身客户端
//                    msg.retain();
//                    entry.getValue().writeAndFlush(msg);
////                }
//            }
//        }else{
//            msg.retain();
//            ctx.fireChannelRead(msg);
//        }
//
//    }
//
//
////        channelGroup.writeAndFlush(new TextWebSocketFrame("aaabbb"));
//
//
//    private void websocketLogin(Map map,ChannelHandlerContext ctx) {
//        String name = map.get("name").toString();
//        cmap.put(name,ctx.channel());
//        System.out.println(name+"登录");
//        System.out.println("cmap "+cmap.toString());
//    }
//
//}
